<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Admin\Controller;
use Think\Controller;
class ContentController extends Controller{
    public function update(){
        $model=D('content');
        $data=$model->read($_GET['id']);
        $this->assign('data',$data);       
        $this->display();
    }
    public function doupdate(){
        $model=D('content');
         if($_FILES['image']['error']==0){
            move_uploaded_file($_FILES['image']['tmp_name'], 'THINK_PATH' ."/../Public/upload/".md5(time()).".png") ; 
            $data['img']='THINK_PATH' ."/../Public/upload/".md5(time()).".png" ;
        }else{
            $data['img']=$_POST['img'];
        }
        $model->updatecontent($_POST['id'],$_POST['version'],$_POST['category'],$_POST['title'],$_POST['body'],$data['img']);
        $this->redirect('./admin/user/lists');
    }
    public function delete(){
        $model=D('content');
       if($_POST['message']){
            $data= $model->deletecontent($_GET['id']); 
            $output=array();
            $output['status']=1;            
            $output['url']=U('lists');
            print json_encode($output);       
            exit;
            }
    }
    public function lists(){
        $model=D('content');
        $data=$model->content();
        $this->assign('data',$data);               
        $this->display();
    }
} 
